/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UTIL;

import com.microsoft.sqlserver.jdbc.SQLServerDriver;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;


public class SqlDataAccessHelper {

    protected static String connectionString;

    public static String getConnectionString() {
        try {
            connectionString = null;
            File file = new File("config\\config.xml");
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            Document doc = docBuilder.parse(file);
            doc.getDocumentElement().normalize();
            connectionString = doc.getFirstChild().getTextContent();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return connectionString;
    }

    public static Connection getConnection() {
        Connection connect = null;
        try {
            DriverManager.registerDriver(new SQLServerDriver());
            connect = DriverManager.getConnection(getConnectionString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return connect;
    }   
}
